<div class="main-content">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <ol class="breadcrumb">
                    <li>
                        <i class="clip-file"></i>
                        <a href="#">
                            Logística
                        </a>
                    </li>
                    <li class="active">
                        Productos
                    </li>					
                </ol>
                <div class="page-header">
                    <h1>Producto <small>Formulario</small></h1>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <!-- start: DYNAMIC TABLE PANEL -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <i class="icon-external-link-sign"></i>
                        Productos
                        <div class="panel-tools">
                            <a class="btn btn-xs btn-link panel-collapse collapses" href="#">
                            </a>
                            <a class="btn btn-xs btn-link panel-config" href="#panel-config" data-toggle="modal">
                                <i class="icon-wrench"></i>
                            </a>
                            <a class="btn btn-xs btn-link panel-refresh" href="#">
                                <i class="icon-refresh"></i>
                            </a>
                            <a class="btn btn-xs btn-link panel-expand" href="#">
                                <i class="icon-resize-full"></i>
                            </a>
                            <!--<a class="btn btn-xs btn-link panel-close" href="#">
                                <i class="icon-remove"></i>
                            </a> -->
                        </div>
                    </div>
                    <div class="panel-body"> 
                        <div class="alert" id="mensaje" style="display: none;"></div>
                        <form id="frmProd" role="form" method="post" class="form-horizontal" >                            
                            <div class="row">
                                <div class="col-md-8"> 
                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label" for="txtDescProd">
                                                    Producto
                                                </label>
                                                <div class="col-sm-9">
                                                    <input type="hidden" id="txtCodProd" value="<?php echo set_value('idProd', $this->form_data->id) ?>" >
                                                    <input type="text" placeholder="Ingrese producto" id="txtDescProd" name="descripcion" value="<?php echo set_value('descripcion', $this->form_data->descripcion) ?>" class="form-control">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label" for="cboMarca">
                                                    Marca
                                                </label>
                                                <div class="col-sm-9">
                                                    <!--<select id="cboMarca" class="form-control search-select">
                                                        <option></option>
                                                    </select> -->
                                                    <?php
                                                    $css = 'class="form-control search-select" id="cboMarca" placeholder="Seleccione Marca"';
                                                    echo form_dropdown("cboMarca", $marcas, $this->form_data->marca, $css);
                                                    ?>
                                                </div>
                                            </div>
                                        </div>                                
                                    </div>
                                    <div class="row">
                                        <div class="col-md-6">                            
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label" for="txtModelo">
                                                    Modelo
                                                </label>
                                                <div class="col-sm-9">
                                                    <input type="text" placeholder="Ingrese modelo" id="txtModelo" value="<?php echo set_value('modelo', $this->form_data->modelo) ?>" name="modelo" class="form-control">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label" for="cboLinea">
                                                    Línea
                                                </label>
                                                <div class="col-sm-9">
                                                    <!--<select id="cboLinea" class="form-control search-select">
                                                        <option></option>
                                                    </select> -->
                                                    <?php
                                                    $css = 'class="form-control search-select" id="cboLinea" placeholder="Seleccione Linea"';
                                                    echo form_dropdown("cboLinea", $lineas, $this->form_data->linea, $css);
                                                    ?>
                                                </div>
                                            </div>
                                        </div>                                
                                    </div>
                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label" for="txtStock">
                                                    Stock
                                                </label>
                                                <div class="col-sm-3">                                            
                                                    <input type="text" id="txtStock" value="0" disabled="disabled" class="form-control">
                                                </div>
                                                <!--<a href="#VntStock" id="btnStock" class="btn btn-primary" data-toggle="modal" ><i class="icon-search"></i></a> -->
                                                <a href="#" id="btnPrueba" class="btn btn-primary" data-toggle="modal" ><i class="icon-search"></i></a>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label" for="cboFamilia">
                                                    Familia
                                                </label>
                                                <div class="col-sm-9">
                                                   <!-- <select id="cboFamilia" class="form-control search-select">
                                                        <option></option>
                                                    </select> -->
                                                    <?php
                                                    $css = 'class="form-control search-select" id="cboFamilia" placeholder="Seleccione Familia"';
                                                    echo form_dropdown("familia", $familias, $this->form_data->familia, $css);
                                                    ?>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label" for="txtStock">
                                                    Color
                                                </label>
                                                <div class="col-sm-8">  
                                                    <?php
                                                    $prop = 'class="form-control search-select" id="colores" placeholder="Seleccione Colores" multiple="multiple"';
                                                    echo form_dropdown("color", $colores, null, $prop);
                                                    ?>                                                   
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <table class="table table-striped table-bordered table-condensed table-hover editable" id="tblTipoPrecio">
                                        <thead>
                                            <tr>
                                                <th class="hidden">Código</th>
                                                <th>Tipo</th>
                                                <th>Cantidad</th>
                                                <th>Precio</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
                                            if (!empty($registros)) :
                                                foreach ($registros as $fila):
                                                    ?>
                                                    <tr>
                                                        <td class='hidden'><?php echo $fila->id_tipoprecio; ?></td>
                                                        <td class='uneditable' style="width: 120px"><?php echo $fila->desc_tipoprecio; ?></td>
                                                        <td style="width: 80px"><?php echo $fila->cantidad == 'cantidad' ? '0' : $fila->cantidad; ?></td>
                                                        <td style="width: 80px"><?php echo $fila->precio == 'precio' ? '0.00' : $fila->precio; ?></td>
                                                    </tr>
                                                    <?php
                                                endforeach;
                                            endif;
                                            ?>       	
                                        </tbody>
                                    </table>  
                                </div>
                            </div>
                            <hr>                          
                            <div class="row">
                                <div class="col-md-4"></div>
                                <div class="col-md-2">
                                    <button class="btn btn-primary btn-block" type="submit" id="guardarProd">
                                        <i class="icon-save"></i>
                                        Guardar                                        
                                    </button>
                                </div>
                                <div class="col-md-2">
                                    <button class="btn btn-danger btn-block" type="button" id="cancelarProd">
                                        <i class="icon-save"></i>
                                        Cancelar                                        
                                    </button>
                                </div>
                                <div class="col-md-4"></div>
                            </div>
                        </form>                        
                    </div>
                </div>
                <!-- end: DYNAMIC TABLE PANEL -->
            </div>
        </div>
    </div>
</div>


<div id="VntStock" class="modal fade" aria-hidden="true" role="dialog" tabindex="-1" style="display: none;">
    <div class="modal-dialog">
        <div class="modal-content" style="width: 400px">
            <div class="modal-header">
                <button class="close" aria-hidden="true" data-dismiss="modal" type="button">
                    ×
                </button>
                <h4 class="modal-title" id="tituFrm">
                    Stock por Almacén
                </h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-1"></div>
                    <div class="col-sm-10">
                        <!-- start: TEXT FIELDS PANEL -->

                        <div class="panel-body">
                            <form role="form" class="form-horizontal" id="">
                                <input type="hidden" id="totalAlm">
                                <div id="frmStkAlm"></div>
                            </form>
                        </div>

                        <!-- end: TEXT FIELDS PANEL -->
                    </div>
                    <div class="col-sm-1"></div>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" id="cerrarFormMarca" data-dismiss="modal" type="button">
                    Cerrar
                </button>
                <button class="btn btn-primary" data-dismiss="modal" type="button" id="agregarStk" > 
                    Guardar
                </button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function() {

        var prod = $("#txtCodProd").val();
        stockProd("<?= base_url("/logistica/proceso/stockProducto/almacen") ?>", prod, 0, "frmStkAlm");
        $("#cboLinea").change(function() {
            $("#cboFamilia option").remove();
            var linea = $("#cboLinea").val();
            if (linea > 0) {
                combo("<?= base_url("logistica/proceso/combo/familia") ?>/" + linea, "cboFamilia");
            }
        });
        $('#frmProd').validate({
            errorElement: "span", // contain the error msg in a span tag
            errorClass: 'help-block',
            errorPlacement: function(error, element) { // render error placement for each input type
                error.insertAfter(element);
            },
            ignore: "",
            rules: {
                descripcion: {
                    minlength: 2,
                    required: true
                },
                modelo: {
                    minlength: 2,
                    required: true
                }
            },
            messages: {
                descripcion: "Por favor, ingrese descripción de un producto.",
                modelo: "Por favor, ingrese modelo del producto."
            },
            highlight: function(element) {
                $(element).closest('.help-block').removeClass('valid');
                // display OK icon
                $(element).closest('.form-group').removeClass('has-success').addClass('has-error').find('.symbol').removeClass('ok').addClass('required');
                // add the Bootstrap error class to the control group
            },
            unhighlight: function(element) { // revert the change done by hightlight
                $(element).closest('.form-group').removeClass('has-error');
                // set error class to the control group
            },
            success: function(label, element) {
                label.addClass('help-block valid');
                // mark the current input as valid and display OK icon
                $(element).closest('.form-group').removeClass('has-error').addClass('has-success').find('.symbol').removeClass('required').addClass('ok');
            }
        });


        $('#frmProd').submit(function(e) {
            e.preventDefault();
            InUp_LogProductos("<?= base_url("logistica/proceso/guardarProductos"); ?>");
        });

        $("#btnPrueba").on('click', function() {
            alert("valor de select: " + $("#colores").val().length);
        });

    });

</script>